var express = require('express');
var co = require('co');
var BlogPost = require('../domain/BlogPost');

var router = express.Router();


// 看什么时候搞一个spring 的 ioc
var blogPost = new BlogPost();
/* GET home page. */
router.get('/', function (req, res, next) {
    co(function *() {
        let focusBlogPost = yield blogPost.findOne(1);
        let sql = "select * from blog_post order by created_at desc limit 0,10";
        let newBlogPostList = yield blogPost.execute(sql, []);
        res.render('index', {focusBlogPost: focusBlogPost[0], newBlogPostList: newBlogPostList});
    });
});

module.exports = router;
